Skip to content

Python SDK design for Http.File when it appears in non-multipart request body and response body (DO NOT MERGE)#3351

Draft
msyyc wants to merge 9 commits intomainfrom
docs/http-file-body-compatibility
Draft

Python SDK design for Http.File when it appears in non-multipart request body and response body (DO NOT MERGE)#3351
msyyc wants to merge 9 commits intomainfrom
docs/http-file-body-compatibility

Conversation

@msyyc
Copy link
Member

@msyyc msyyc commented Feb 25, 2026

No description provided.

msyyc and others added 6 commits February 25, 2026 10:01
Add a compact design note explaining why TypeSpec Http.File emitting IO[bytes] | bytes is backward compatible with legacy Swagger file APIs that accepted bytes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@msyyc msyyc changed the title docs: clarify Http.File request body compatibility Python SDK design for Http.File when it appears in non-multipart request body and response body (DO NOT MERGE) Feb 25, 2026
### Generated Python SDK

```python
def download(self, **kwargs) -> bytes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loses both content type and suggested file name. And it is a very dangerous operation for large amounts of data.

Copy link
Member Author

@msyyc msyyc Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For

  @route("/base64")
  @scenario
  @scenarioDoc("""
    Test base64 encode for bytes body.
    Expected body:
    "dGVzdA==" (base64 encode of test, in JSON string)
    """)
  op base64(): {
    @header
    contentType: "application/json";

    @body
    @encode(BytesKnownEncoding.base64)
    value: bytes;
  };

Python SDK API will decode it with base64 like

. But what if "content-type" is "application/json" but the response body is not encoded with base64 like this case: https://github.com/microsoft/typespec/blob/4d4afdabef3fed9b2d5f017a61e34286970bbff2/packages/http-specs/specs/type/file/main.tsp#L39-L47. Then typespec type bytes can't work and only Http.File could reprensent this scenario.

That's my understanding why we need Http.File as response body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants